/*
 //相关人，组织字段
 const ABPropertyID kABPersonKindProperty;
 const CFNumberRef kABPersonKindPerson;
 const CFNumberRef kABPersonKindOrganization;
 
 // 电话相关字段
 AB_EXTERN const ABPropertyID kABPersonPhoneProperty;
 AB_EXTERN const CFStringRef kABPersonPhoneMobileLabel;
 AB_EXTERN const CFStringRef kABPersonPhoneIPhoneLabel
 AB_EXTERN const CFStringRef kABPersonPhoneMainLabel;
 AB_EXTERN const CFStringRef kABPersonPhoneHomeFAXLabel;
 AB_EXTERN const CFStringRef kABPersonPhoneWorkFAXLabel;
 AB_EXTERN const CFStringRef kABPersonPhoneOtherFAXLabel
 AB_EXTERN const CFStringRef kABPersonPhonePagerLabel;
 
 // 即时聊天信息相关字段
 AB_EXTERN const ABPropertyID kABPersonInstantMessageProperty;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceKey;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceYahoo;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceJabber;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceMSN;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceICQ;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceAIM;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceQQ
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceGoogleTalk;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceSkype;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceFacebook;
 AB_EXTERN const CFStringRef kABPersonInstantMessageServiceGaduGadu;
 AB_EXTERN const CFStringRef kABPersonInstantMessageUsernameKey;
 
 // 个人网页相关字段
 AB_EXTERN const ABPropertyID kABPersonURLProperty;
 AB_EXTERN const CFStringRef kABPersonHomePageLabel;
 //相关人姓名字段
 AB_EXTERN const ABPropertyID kABPersonRelatedNamesProperty;
 AB_EXTERN const CFStringRef kABPersonFatherLabel;    // Father
 AB_EXTERN const CFStringRef kABPersonMotherLabel;    // Mother
 AB_EXTERN const CFStringRef kABPersonParentLabel;    // Parent
 AB_EXTERN const CFStringRef kABPersonBrotherLabel;   // Brother
 AB_EXTERN const CFStringRef kABPersonSisterLabel;    // Sister
 AB_EXTERN const CFStringRef kABPersonChildLabel;      // Child
 AB_EXTERN const CFStringRef kABPersonFriendLabel;    // Friend
 AB_EXTERN const CFStringRef kABPersonSpouseLabel;    // Spouse
 AB_EXTERN const CFStringRef kABPersonPartnerLabel;   // Partner
 AB_EXTERN const CFStringRef kABPersonAssistantLabel; // Assistant
 AB_EXTERN const CFStringRef kABPersonManagerLabel;   // Manager
 */

import UIKit
import AddressBookUI

class Contact: NSObject {
    var isSelected = false
    
    var contactRecord: ABRecord?
    // 姓
    var lastName: String = ""
    // 名
    var firstName: String = ""
    // 昵称
    var nikeName: String = ""
    // 公司(组织)
    var organization: String = ""
    // 职位
    var jobTitle: String = ""
    // 部门
    var department: String = ""
    // 备注
    var note: String = ""
    // 电话
    var contactPhones: [ContactPhone] = []
    // Email
    var contactEmails: [ContactEmail] = []
    // 地址
    var contactAddresss: [ContactAddress] = []
    // 中间名
    var middlename: String = ""
    // prefix前缀
    var prefix: String = ""
    // suffix后缀
    var suffix = ""
    // 姓拼音
    var firstnamePhonetic = ""
    // 中间名拼音
    var middlenamePhonetic = ""
    // 名拼音
    var lastnamePhonetic =  ""
    // 生日
    var birthday: NSDate?
    // 创建联系人时间
    var firstknow =  ""
    // 最后一次修改联系人时间
    var lastknow = ""
    
    init(contact: ABRecord) {
        contactRecord = contact
        
        // 姓
        lastName = ABRecordCopyValue(contact, kABPersonLastNameProperty)?.takeRetainedValue() as? String ?? ""
        
        // 名
        firstName = ABRecordCopyValue(contact, kABPersonFirstNameProperty)?.takeRetainedValue() as? String ?? ""
        
        // 昵称
        nikeName = ABRecordCopyValue(contact, kABPersonNicknameProperty)?.takeRetainedValue() as? String ?? ""
        
        // 中间名
        middlename = ABRecordCopyValue(contact, kABPersonMiddleNameProperty)?.takeRetainedValue() as? String ?? ""
        
        // 公司（组织）
        organization = ABRecordCopyValue(contact, kABPersonOrganizationProperty)?.takeRetainedValue() as? String ?? ""
        
        // 职位
        jobTitle = ABRecordCopyValue(contact, kABPersonJobTitleProperty)?.takeRetainedValue() as? String ?? ""
        
        // 部门
        department = ABRecordCopyValue(contact, kABPersonDepartmentProperty)?.takeRetainedValue() as? String ?? ""
        
        // 备注
        note = ABRecordCopyValue(contact, kABPersonNoteProperty)?.takeRetainedValue() as? String ?? ""
        
        // prefix前缀
        prefix = ABRecordCopyValue(contact, kABPersonPrefixProperty)?.takeRetainedValue() as? String ?? ""
        
        // suffix后缀
        suffix = ABRecordCopyValue(contact, kABPersonSuffixProperty)?.takeRetainedValue() as? String ?? ""
        
        // 姓氏拼音
        firstnamePhonetic = ABRecordCopyValue(contact, kABPersonLastNamePhoneticProperty)?.takeRetainedValue() as? String ?? ""
        
        // 名拼音
        lastnamePhonetic = ABRecordCopyValue(contact, kABPersonLastNamePhoneticProperty)?.takeRetainedValue() as? String ?? ""
        
        // 中间名拼音
        middlenamePhonetic = ABRecordCopyValue(contact, kABPersonMiddleNamePhoneticProperty)?.takeRetainedValue() as? String ?? ""
        
        // 生日
        birthday = ABRecordCopyValue(contact, kABPersonBirthdayProperty)?.takeRetainedValue() as? NSDate
        
        // 创建联系人时间
        firstknow = ABRecordCopyValue(contact, kABPersonCreationDateProperty)?.takeRetainedValue() as? String ?? ""
        
        // 最后一次修改联系人时间
        lastknow = ABRecordCopyValue(contact, kABPersonModificationDateProperty)?.takeRetainedValue() as? String ?? ""
        
        // 获取电话
        if let phoneValues: ABMutableMultiValue = ABRecordCopyValue(contact, kABPersonPhoneProperty).takeRetainedValue() {
            contactPhones = ContactPhone.contactPhones(phoneValues)
        }
        
        //获取Email
        if let emailValues:ABMutableMultiValueRef = ABRecordCopyValue(contact, kABPersonEmailProperty).takeRetainedValue() {
            contactEmails = ContactEmail.contactEmails(emailValues)
        }
        
        //获取地址
        if let addressValues:ABMutableMultiValueRef = ABRecordCopyValue(contact, kABPersonAddressProperty).takeRetainedValue() {
            contactAddresss = ContactAddress.contactAddresss(addressValues)
        }
    }
}